/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util.entityhelper;
import entity.ReservationEntity;
import entity.FnBReservationEntity;
import entity.ReservedMealEntity;
import entity.ReservedFnBProductEntity;
import entity.ReservedSetMealEntity;
import java.util.Date;
import java.util.List;
import java.sql.Time;
import java.util.ArrayList;
/**
 *
 * @author NGUYEN CONG DAT
 */
public class AccumulationHelper {
    private ReservationEntity reservation;
    private List<ReservedFnBProductEntity> reservationComponent;
    private Double totalPoint;
    private Double totalBill;
    private Date reservationDate;
    private Time reservationTime;
    private Integer numberOfPeople;
    
    public AccumulationHelper() {     
    }
    
    public AccumulationHelper(ReservationEntity reservation) {
        reservationComponent = new ArrayList<ReservedFnBProductEntity>(); 
        this.reservation = reservation;
        calculate();
    }
     
    public ReservationEntity getReservation() {
        return reservation;
    }

    public void setReservation(ReservationEntity reservation) {
        this.reservation = reservation;
    }

    public Double getTotalPoint() {
        return totalPoint;
    }

    public void setTotalPoint(Double totalPoint) {
        this.totalPoint = totalPoint;
    }
    
    // Support method to calculate the number of point stemming from the reservation
    private void calculate() {
        double point = 0;
        double billValue = 0;
        if (reservation instanceof FnBReservationEntity) {
            FnBReservationEntity fnBReservation = (FnBReservationEntity) reservation;
            for (ReservedSetMealEntity obj: fnBReservation.getReservedSetMeal()) {
                point = point + obj.getPointReceived()*obj.getQuantity();
                getReservationComponent().add((ReservedFnBProductEntity)obj);
                billValue = billValue + obj.getPrice()*obj.getQuantity();
            }
            for (ReservedMealEntity obj: fnBReservation.getReservedMeal()) {
                point = point + obj.getPointReceived()*obj.getQuantity();
                getReservationComponent().add((ReservedFnBProductEntity)obj);
                billValue = billValue + obj.getPrice()*obj.getQuantity();
            }
            setReservationDate(fnBReservation.getDateReserved());
            setReservationTime(fnBReservation.getTimeBegin());
            setNumberOfPeople(fnBReservation.getNoOfPeople());
        }
        setTotalPoint(point);
        setTotalBill(billValue);
    }

    public Date getReservationDate() {
        return reservationDate;
    }

    public void setReservationDate(Date reservationDate) {
        this.reservationDate = reservationDate;
    }

    public Double getTotalBill() {
        return totalBill;
    }

    public void setTotalBill(Double totalBill) {
        this.totalBill = totalBill;
    }

    public List<ReservedFnBProductEntity> getReservationComponent() {
        return reservationComponent;
    }

    public void setReservationComponent(List<ReservedFnBProductEntity> reservationComponent) {
        this.reservationComponent = reservationComponent;
    }

    public Time getReservationTime() {
        return reservationTime;
    }

    public void setReservationTime(Time reservationTime) {
        this.reservationTime = reservationTime;
    }

    public Integer getNumberOfPeople() {
        return numberOfPeople;
    }

    public void setNumberOfPeople(Integer numberOfPeople) {
        this.numberOfPeople = numberOfPeople;
    }
}
